﻿import QtQuick
import QtQuick.Layouts

Rectangle{
    id:bottomBarRoot
    //left
    property int leftMargin
    property int rightMargin
    property int btnIconSize: 25
    property int albumSize: 65

    RowLayout{
        anchors.fill: parent
        spacing: 16

        //左部
        Row{
            Layout.alignment: Qt.AlignVCenter
            Layout.leftMargin: 25
            spacing: 6
            Album{
                sideLength: albumSize
                MouseArea{
                    anchors.fill: parent
                    hoverEnabled: true
                    acceptedButtons: Qt.LeftButton
                    // 根据鼠标位置动态决定光标
                    cursorShape: {
                        const cx = width/2, cy = height/2, r = Math.min(width, height)/2
                        const dx = mouseX - cx, dy = mouseY - cy
                        return (dx*dx + dy*dy <= r*r) ? Qt.PointingHandCursor : Qt.ArrowCursor
                    }

                    // 如果还要点击只在圆内有效：
                    onPressed: (ev) => {
                                   const cx = width/2, cy = height/2, r = Math.min(width, height)/2
                                   const dx = ev.x - cx, dy = ev.y - cy
                                   if (dx*dx + dy*dy > r*r)
                                   ev.accepted = false;  // 放行给下面的项
                               }
                }
            }


            Column{
                anchors.verticalCenter: parent.verticalCenter
                spacing: 6
                MarqueeText{
                    id:songName
                    text:"未知歌曲名超级无敌长长存储池出出出纯纯粹粹纯纯粹粹处处长"
                    //height: 40
                    width: 200
                    color: "red"
                    font{
                        pixelSize: 16
                        family: "宋体"
                    }

                }

                MarqueeText{
                    id: singerName
                    text:"未知unknown"
                    width: 100
                    color:Qt.lighter("grey",0.6)
                    font{
                        pixelSize: 15
                        family: "宋体"
                    }
                }

                SequentialAnimation {
                    id:textAni
                }
            }
        }








    }



    //中部
    Item{
        anchors.fill: parent
    Row{
        id:centerPart
        //用anchors.centIn:parent 会出现半像素对齐问题
        anchors.centerIn: parent

        property Item iconTarget
        property real hoveredScale:0.8


        spacing: 10
        //上一首
        NoFrameButton{
            id: btnPrev
            anchors.verticalCenter: parent.verticalCenter
            needHoverTimer: true
            smooth: false
            icon{
                width:btnIconSize
                height:btnIconSize
                source: "qrc:/images/houtiao.png"
            }

            onIsHoveredChanged: {
                if(isHovered){
                    centerPart.iconTarget = btnPrev
                    seqAni.stop()
                    seqAni.start()
                }
            }
        }
        //播放
        NoFrameButton{
            id: btnPlay
            anchors.verticalCenter: parent.verticalCenter
            needHoverTimer: true
            smooth: false
            icon{
                width:btnIconSize + 10
                height:btnIconSize + 10
                source: "qrc:/images/bofang.png"
            }

            onIsHoveredChanged: {
                if(isHovered){
                    centerPart.iconTarget = btnPlay
                    seqAni.stop()
                    seqAni.start()
                }
            }

        }

        NoFrameButton{
            id: btnNext
            anchors.verticalCenter: parent.verticalCenter
            needHoverTimer: true
            smooth: false
            icon{
                width:btnIconSize
                height:btnIconSize
                source: "qrc:/images/kuaijin.png"
            }

            onIsHoveredChanged: {
                if(isHovered){
                    centerPart.iconTarget = btnNext
                    seqAni.stop()
                    seqAni.start()
                }
            }

        }

        SequentialAnimation{
            id:seqAni

            ScaleAnimator{
                target: centerPart.iconTarget
                from: 1
                to:centerPart.hoveredScale
                duration: 200
            }

            ScaleAnimator{
                target: centerPart.iconTarget
                from: centerPart.hoveredScale
                to:1
                duration:300
            }
        }
    }
}



    function setAlbumSource(url){
        alb.source = url
    }

    function setSongName(name){
        songName.text = name
    }
    function setSingerName(name){
        singerName.text = name
    }
}
